const maxAreaOfisland = (grid) => {
  const row = grid.length, col = grid[0].length
  let res = 0
  const DFS = (i, j) => {
    // 下标越界返回0
    if (i < 0 || i >= row || j < 0 || j >= col) {
      return 0
    }
    // 值为0返回0
    if (grid[i][j] == 0) { return 0 }
    // 访问过后置为0，防止重复访问
    grid[i][j] = 0
    // 递归计算岛屿面积
    return 1 + DFS(i, j - 1) + DFS(i - 1, j) + DFS(i, j + 1) + DFS(i + 1, j)
  }
  // 遍历二维数组
  for (let i = 0; i < row; i++) {
    for (let j = 0; j < col; j++) {
      if (grid[i][j] == 1) {
        res = Math.max(res, DFS(i, j))
      } else {
        continue
      }
    }
  }
  return res
}
const grid = [[0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0]]

console.log(maxAreaOfisland(grid));